<template>
  <div>
    <!--面包屑导航-->
    <el-breadcrumb separator="/" style="padding-left: 10px;padding-bottom: 10px;font-size: 12px">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">系统管理</a></el-breadcrumb-item>
      <el-breadcrumb-item><a href="#">出库管理</a></el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片-->
    <el-card class="box-card">

      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="操作人员名称:" label-width="110px">
          <el-input v-model="formInline.operator" placeholder="请输入操作人员名称"></el-input>
        </el-form-item>

        <el-form-item style="margin-left: 10px">
          <el-button icon="el-icon-refresh" v-on:click="clearOutStock">重置</el-button>
          <el-button type="primary" icon="el-icon-search" v-on:click="queryOutStockName"><a >查询</a></el-button>
          <el-button type="success" icon="el-icon-plus" v-on:click="dialogVisible=true">添加</el-button>
          <el-button type="warning" icon="el-icon-download" ><a href="http://localhost:8090/outStock/exportOutStockToExcel">导出</a></el-button>
        </el-form-item>
        <el-form-item prop="file">
          <el-upload
            class="upload-demo"
            ref="upload"
            multiple
            accept=".xls"
            action=""
            :http-request="httpRequest"
            :file-list="fileList"
            :auto-upload="false"
          >
            <el-button slot="trigger"  type="primary">选取文件</el-button>
            <el-button style="margin-left:5px" type="danger" icon="el-icon-upload"  @click="submitUploadList">导入</el-button>
          </el-upload>
        </el-form-item>
      </el-form>


      <!--表格内容显示区域-->
      <el-table
        :data="outStockList"
        border
        max-height="400px"
        style="width: 100%;height: 400px;">
        <el-table-column
          prop="id"
          label="编号"
          width="50">
        </el-table-column>
        <el-table-column
          prop="outNum"
          label="订单编号"
          width="280">
        </el-table-column>
        <el-table-column
          prop="operator"
          label="操作人员"
          width="140">
        </el-table-column>
        <el-table-column
          sortable
          prop="createTime"
          label="出库时间"
          width="170">
        </el-table-column>
        <el-table-column
          sortable
          prop="productNumber"
          label="出库总数"
          width="110">
        </el-table-column>
        <el-table-column
          sortable
          prop="name"
          label="消费者"
          width="140">
        </el-table-column>

        <el-table-column
          prop="status"
          label="状态"
         width="100">
          <template slot-scope="scope">
            {{scope.row.status == 0 ? '正常出库':(scope.row.status == 1 ? '已进入回收' : '等待审核')}}
          </template>
        </el-table-column>

        <el-table-column
          prop="priority"
          label="紧急程度"
          width="80">
          <template slot-scope="scope">
            {{scope.row.priority == 1 ? '不急':scope.row.priority == 2 ? '常规':(scope.row.priority==3 ? ' 紧急':'特急')}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope" >
          <el-button type="primary" size="mini" icon="el-icon-edit" v-on:click="queryOutStockById(scope.row)">修改</el-button>
           <el-button type="danger" size="mini" icon="el-icon-delete"  > 删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="padding-top: 15px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <!--添加弹窗-->
    <el-dialog title="添加" :visible.sync="dialogVisible" width="32%">
    <el-form ref="form" :model="outStockForm" label-width="100px">
      <el-form-item label="类别:">
        <template >
          <el-radio-group v-model="outStockForm.type">
            <el-radio :label="0">直接出库</el-radio>
            <el-radio :label="1">审核出库</el-radio>
          </el-radio-group>
        </template>
      </el-form-item>
      <el-form-item label="操作人员:">
        <el-input v-model="outStockForm.operator"></el-input>
      </el-form-item>
      <el-form-item label="消费者编号:">
        <el-input v-model="outStockForm.consumerId"></el-input>
      </el-form-item>
      <el-form-item label="出库时间:">
        <div>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="outStockForm.createTime"
            type="datetime"
            style="width:100%;"
            placeholder="选择日期时间"
            align="right"
            :picker-options="pickerOptions1">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item label="出库总数:">
        <el-input v-model="outStockForm.productNumber"></el-input>
      </el-form-item>
      <el-form-item label="描述信息:">
        <el-input v-model="outStockForm.remark"></el-input>
      </el-form-item>
      <el-form-item label="状态:">
        <template >
          <el-radio-group v-model="outStockForm.status">
            <el-radio :label="0">正常入库单</el-radio>
            <el-radio :label="1">已进入回收</el-radio>
            <el-radio :label="2">等待审核</el-radio>
          </el-radio-group>
        </template>
      </el-form-item>
      <el-form-item label="紧急程度:">
        <template >
          <el-radio-group v-model="outStockForm.priority">
            <el-radio :label="1">不急</el-radio>
            <el-radio :label="2">常规</el-radio>
            <el-radio :label="3">紧急</el-radio>
            <el-radio :label="4">特急</el-radio>
          </el-radio-group>
        </template>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addOutStock">确 定</el-button>
      </span>
  </el-dialog>
<!--修改弹窗-->
<!--    <el-dialog title="修改" :visible.sync="dialogOutStock" width="30%">-->
<!--      <el-form ref="form" :model="outStockUpdateList" label-width="80px">-->
<!--        <el-form-item label="操作人员:">-->
<!--          <el-input v-model="outStockUpdateList.operator"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备注:">-->
<!--          <el-input v-model="outStockUpdateList.remark"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建时间:">-->
<!--          <div>-->
<!--            <el-date-picker-->
<!--              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--              v-model="outStockUpdateList.createTime"-->
<!--              type="datetime"-->
<!--              style="width:100%;"-->
<!--              placeholder="选择日期时间"-->
<!--              align="right"-->
<!--              :picker-options="pickerOptions1">-->
<!--            </el-date-picker>-->
<!--          </div>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="状态:">-->
<!--          <template >-->
<!--            <el-radio-group v-model="outStockUpdateList.status">-->
<!--              <el-radio :label="0">正常入库单</el-radio>-->
<!--              <el-radio :label="1">已进入回收</el-radio>-->
<!--              <el-radio :label="2">等待审核</el-radio>-->
<!--            </el-radio-group>-->
<!--          </template>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <span slot="footer" class="dialog-footer">-->
<!--        <el-button @click="dialogOutStock = false">取 消</el-button>-->
<!--        <el-button type="primary" @click="updateInStock">确 定</el-button>-->
<!--      </span>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
  import { queryAllOutStockByPage } from '../../api/outStock';

  export default {
    name: 'InStock',
    data () {
      return {
        pageSize: 6,
        total: 1,
        current: 1,
        formInline: {
          operator:''
        },
        suppliers: [],
        outStockList: null,
        fileList: [],
        loadUrl:'outStock/importOutStockToExcel',
        dialogVisible:false,
        dialogOutStock:false,
        outStockForm: {},
        outStockUpdateList: {},
        pickerOptions1: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
      }
    },
    methods: {
      // 提交事件
      onSubmit () {
        console.log('submit!')
      },
      //导入数据
      httpRequest(param) {
        console.log(param);
        let fileObj = param.file; // 相当于input里取得的files
        let fd = new FormData(); // FormData 对象
        fd.append("file", fileObj); // 文件对象
        let url = this.loadUrl
        let config = {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        };
        this.$http.post(url, fd, config).then((res) => {
          console.log(res);
        });
      },
      //导入提交
      submitUploadList() {
        this.$refs.upload.submit();
      },
      // 当记录数发生改变时
      handleSizeChange (val) {
        this.pageSize = val;
        let operator=this.formInline.operator;
        this.getOutStockList(this.current,this.size,operator);
      },
      // 当前页发生改变时
      handleCurrentChange (val) {
        let operator=this.formInline.operator;
        this.current = val;
        this.getOutStockList(this.current,this.pageSize,operator);
      },
      // 获取出库单数据
      async getOutStockList() {
        let operator=this.formInline.operator;
        const { data } = await queryAllOutStockByPage(this.current,this.pageSize,operator);
        this.outStockList = data.data.outStockPage.records;
        this.total = data.data.outStockPage.total;
        this.pageSize = data.data.outStockPage.size;
      },
      //添加出库单信息
      async addOutStock(){
        let operator=this.formInline.operator;
        let url='outStock/insertOutStock'
        this.$http.post(url, this.outStockForm).then((res) => {
          console.log(res);
          this.$message({
            type: "info",
            message: "保存成功",
          });
          this.dialogVisible = false;
          this.getOutStockList(this.current,this.pageSize,operator);
        }).catch(ex=>this.$message({
          type: "error",
          message: "保存失败",
        }));

      },
      //模糊查询入库单信息
  async queryOutStockName(){
        let operator=this.formInline.operator;
        const { data } =  await queryAllOutStockByPage(1,this.pageSize,operator);
        this.outStockList = data.data.outStockPage.records;
        this.total = data.data.outStockPage.total;
        this.pageSize = data.data.outStockPage.size;
      },
      //清空查询条件
      async clearOutStock(){
        let operator=this.formInline.operator='';
        this.getOutStockList(this.current,this.pageSize,operator);
      },
      //修改出库单
      async updateInStock(){
        let operator=this.formInline.operator;
        let url='outStock/updateOutStockById'
       this.$http.post(url, this.outStockUpdateList).then((res) => {
          console.log(res);
         this.$message({
           type: "info",
           message: "保存成功",
         });
         this.dialogOutStock = false;
         this.getOutStockList(this.current,this.size,operator);
        }).catch(ex=>this.$message({
         type: "error",
         message: "保存失败",
       }));
      },
      //获取当前选中用户信息
      async queryOutStockById(row){
        this.outStockUpdateList=row;
        this.dialogOutStock=true;
      },
    },
    // create创建完成后钩子函数
    created () {
      this.getOutStockList();
    }
  }
</script>

<style scoped>
  a {
    text-decoration: none;
    color:white;
  }
  /*正常的未被访问过的链接*/
  a:link {
    text-decoration: none;
  }
  /*已经访问过的链接*/
  a:visited {
    text-decoration: none;
  }
  /*鼠标划过(停留)的链接*/
  a:hover {
    text-decoration: none;
  }
  /* 正在点击的链接，鼠标在元素上按下还没有松开*/
  a:active {
    text-decoration: none;
  }
  /* 获得焦点的时候 鼠标松开时显示的颜色*/
  a:focus {
    text-decoration: none;
  }
  .upload-demo input{
    display: none;
  }
</style>
